package org.kotemaru.gae.dstool.client.gui;
import org.kotemaru.browser.*;
import org.mortbay.log.Log;

import java.net.URI;

public class DsToolGui extends ActionBrowserFrame {
	static final String FIN_OAUTH_URL =
		"https://www.google.com/accounts/OAuthAuthorizeToken";
		
	public DsToolGui() {
		super("DsTool",
				DsToolGui.class.getPackage().getName());
	}
	
	
	public boolean isAllowUrl(String url) {
		try {
			if (super.isAllowUrl(url)) return true;
			URI uri = new URI(url);
			String host = uri.getHost();
			return host != null && (
				host.endsWith("google.com")
				|| host.endsWith("appspot.com")
			);
		} catch (Exception e) {
			Log.warn(e);
			return false;
		}
	}

	public /*abstract*/ void onload(String url) {
		if (FIN_OAUTH_URL.equals(url)) {
			// auto redirect oauth finish.
			setUrl("http://action/OAuth?submit=finish");
		}
		super.onload(url);
	}
	
//------------------------------------------------------
	public static void main(String[] args) {
		DsToolGui frame = new DsToolGui();
		frame.layout(800, 600);
		frame.setUrl("http://action/Main");
		frame.run();
	}
}
